<?php 
function cutstr($str, $i, $stopper) {
   $str = htmlspecialchars($str);
   if (strlen($str) > $i){
      $str = substr($str, 0, $i);
      $str .= $stopper;
   }
   return $str;
}
?>

<?php if(count($cartpoolData["shoppingList"]) == 0){ ?>
<div class="grid_720_5 alpha omega">
first time user animatieke, of uitleg
</div>
<?php } 

foreach($cartpoolData["shoppingList"] as $list){ ?>

<div class="grid_720_5 alpha omega">
	<div class="grid_720_2 alpha">
		<h1>Shopping list <?php if($list->closed != ""){ ?>closed<?php } ?></h1>
	</div>
	
	<div class="grid_720_3 omega">
		<span class="listNavButtons">
			<?php if(($list->offset+1) < $list->amount){ ?><a class="previousList" title="previous list" href="#">&lt;</a><?php }else{ ?><span>&nbsp;</span><?php } ?>
			<?php if($list->offset != 0){ ?><a class="nextList" title="next list" href="#">&gt;</a><?php }else{ ?><span>&nbsp;</span><?php } ?>
		</span>
		<span id="datepicker" title="date the list was created"><?php echo $list->created; ?></span>
	</div>
	
</div>	

<span id="shoppingListId" class="hidden"><?php echo $list->id ?></span>
<span id="shoppingListOffset" class="hidden"><?php echo $list->offset ?></span>
<span id="shoppingListClosed" class="hidden"><?php echo $list->closed ?></span>
<!-- <?php echo $list->amount-$list->offset; ?> / <?php echo $list->amount; ?> -->		

<span id="shoppingList">

	<?php
	$i = 0;
	if($list->products){
	foreach($list->products as $product){
		$id = $product->id;
		if($i++&1) { $evenOdd = "even"; } else { $evenOdd = "odd"; }
		if($product->customer == $cartpoolData["sessionData"]["name"]){ $mine = true; }else{ $mine = false; }

	?>
		
		<input type="hidden" name="product_id" value="<?php echo $product->id; ?>" />
		<div class="<?php echo $mine ? "mine": "theirs" ?> <?php echo $evenOdd; ?>">
			<span class="remove">
				<?php if($mine && $list->closed == "") { ?><a class="decreaseQty" rel="<?php echo $id; ?>" title="-1" href="#">-</a><?php }else{ ?>&nbsp;<?php } ?>
			</span>
			
			<span class="qty"><?php echo $product->qty; ?></span>
			
			<span class="add">
				<?php if($mine && $list->closed == "") { ?><a class="increaseQty" rel="<?php echo $id; ?>" title="+1" href="#">+</a><?php }else{ ?>&nbsp;<?php } ?>
			</span>
			
			<span class="middle" style="width:<?php if($list->paidby != ""){ echo '266'; }else{ echo '318'; } ?>px;">
				<span class="product"><?php if($list->paidby != ""){ echo cutstr($product->product, 28, ".."); }else{ echo cutstr($product->product, 50, "..."); }; ?></span>
				<span class="person" <?php if($list->paidby == ""){ ?>style="right: 48px;"<?php } ?>><?php echo cutstr($product->customer, 15, ".."); ?></span>
			</span>
			
			<?php if($list->paidby != ""){ ?><span class="price">&#8364;</span><?php } ?>
			<?php if($list->paidby != ""){ ?><input <?php if($list->closed != "" || $list->paidby != $cartpoolData["sessionData"]["name"]){ ?>readonly<?php }?> tabindex="<?php echo $i; ?>" class="price" rel="<?php echo $id; ?>" name="price" type="text" value="<?php echo number_format($product->price, 2); ?>" /><?php } ?>
			 			
			<span class="comments">
				<?php if($mine && $list->closed == "") { ?><a class="addComments" title="add comments" rel="<?php echo $id; ?>" href="#">...</a><?php }else{ ?>&nbsp;<?php } ?>
			</span>
			<span class="delete">
				<?php if($mine && $list->closed == "") { ?><a class="delete" rel="<?php echo $id; ?>" title="delete" id="delete" href="#">x</a><?php }else{ ?>&nbsp;<?php } ?>
			</span>
		</div>
	
		<?php if(!($product->comments == "" || $product->comments == " ")){ ?>
		<div class="<?php echo $evenOdd; ?> comment">
			<textarea <?php if($list->closed != "" || !$mine) { ?>disabled="disabled"<?php } ?> rel="<?php echo $id; ?>" class="<?php echo $mine ? "mine": "theirs" ?>"><?php echo $product->comments; ?></textarea>
		</div>
		<?php } ?>
	<?php } ?>
	
	

	<?php } ?>
	
	<?php if($list->paidby != ""){	?>
	<div class="total">
		<?php if($list->closed == ""){ ?>
			<?php if($list->paidby == $cartpoolData["sessionData"]["name"]){ ?>
				<span>Press finished when ready.</span>
			<?php }else{ ?>
				<span><?php echo $list->paidby ?> is paying</span>			
			<?php } ?>
		<?php }else{ ?>
			<span>Paid by: <?php echo $list->paidby ?></span>			
		<?php } ?>
		&#8364; <?php echo number_format($list->total, 2); ?>
	</div>
	<?php } ?>
	
	<span class="buttons">
		<input class="button print" type="button" value="Print" />
		<?php if($list->closed == ""){ ?>
			<?php if($list->paidby == ""){	?><input class="button pay" rel="<?php echo $list->id ?>" type="button" value="I'm Paying" /><?php } ?>
			<?php if($list->paidby == $cartpoolData["sessionData"]["name"]){	?><input class="button close" rel="<?php echo $list->id ?>" type="button" value="Finished" /><?php } ?>
		<?php } ?>
	</span>
	
</span>

<?php } ?>